function cont = FreeSpace
% Checks whether or not there is enough disk space available to run the
% full programma. cont may either be 1 or 0, with 1 meaning there is enough
% free space to run the application.
%
% Based on:
% http://www.mathworks.com/matlabcentral/newsreader/view_thread/155791

%% Calculates free disk space
import java.io.*;

    disk=File('..'); % top of system path, aka the harddrive
    Free = get(disk,'UsableSpace'); % this function tell the amount of disk
    % space which is free to use.

%% Defines disk space requirement
    MB = 1024*1024;
    Req = 25*MB; % Minimal disk space required.
    
%%
if Free < Req
    cont = 0; % In case the system doesn't have enough usable space, we won't
    % allow the application to run.
    msgbox('Not enough free disk space!','Error','Error')
    beep % People pay more attention when something beeps :)
else
    cont = 1; % R
    disp('Enough Free space')
end  


end